### Loading in the Data ###
setwd("")
data<-read.csv("02_Clean Racial Shift Full Replication Proprietary.csv")

library(dplyr)
library(sandwich)
library(lmtest)
library(stargazer)
library(ggplot2)
library(RColorBrewer)
library(ggsignif)
Nicole_theme<- ggplot2:: theme(plot.title=element_text(face="bold", size=22), 
                               axis.title.y=element_text(size=20), 
                               axis.text=element_text(size=14),
                               axis.title.x=element_text(size=20),
                               legend.title = element_text(size=20),
                               legend.text = element_text(size=14))

tot_n <- nrow(data)

#### Filtering the Data to Only Include Participants Who Did Not Straight Line ####
data <- data %>%
  filter(!(Trump_FT == Biden_FT & Biden_FT == Swift_FT & Swift_FT == Kimmel_FT))

## To print in appendix on share dropped
1-(nrow(data)/tot_n)

##### Regressions, Linear Hypothesis Tests, and Cohen's D Calculations for Each Dependent Variable #####

### Subjective Manipulation Checks ###
SMC_reg1<-lm(trends_closed_demog~ Treatment, data= data)
SMC_reg1<-coeftest(SMC_reg1, vcov= vcovHC, type= "HC1") 

SMC_reg2<-lm(trends_closed_pol~ Treatment, data= data)
SMC_reg2<-coeftest(SMC_reg2, vcov= vcovHC, type= "HC1") 


SMC_reg3<-lm(trends_closed_media~ Treatment, data= data)
SMC_reg3<-coeftest(SMC_reg3, vcov= vcovHC, type= "HC1") 

### Status Change ###
SC1<-lm(SC_scale~ Treatment, data= data)
SC1<-coeftest(SC1, vcov= vcovHC, type= "HC1") 

### Psychological Mechanisms ###
# symbolic threat
Scale_reg1<-lm(ST_scale~ Treatment, data= data)
Scale_reg1<-coeftest(Scale_reg1, vcov= vcovHC, type= "HC1") 

# realistic threat
Scale_reg2<-lm(RT_scale~ Treatment, data= data)
Scale_reg2<-coeftest(Scale_reg2, vcov= vcovHC, type= "HC1") 

# prototypicality threat
Scale_reg3<-lm(PT_scale_full~ Treatment, data= data)
Scale_reg4<-coeftest(Scale_reg3, vcov= vcovHC, type= "HC1") 

### Group Attitudes ###
# views of black americans
FT_reg1<-lm(Black_FT~ Treatment, data= data)
FT_reg1<-coeftest(FT_reg1, vcov= vcovHC, type= "HC1") 

# views of latino americans
FT_reg2<-lm(Latinos_FT~ Treatment, data= data)
FT_reg2<-coeftest(FT_reg2, vcov= vcovHC, type= "HC1") 

# views of asian americans
FT_reg3<-lm(Asian_FT~ Treatment, data= data)
FT_reg3<-coeftest(FT_reg3, vcov= vcovHC, type= "HC1") 

# views of white americans
FT_reg4<-lm(White_FT~ Treatment, data= data)
FT_reg4<-coeftest(FT_reg4, vcov= vcovHC, type= "HC1") 

# views of blm
FT_reg5<-lm(BLM_FT~ Treatment, data= data)
FT_reg5<-coeftest(FT_reg5, vcov= vcovHC, type= "HC1") 

# views of the alt-right
FT_reg6<-lm(Alt_Right_FT~ Treatment, data= data)
FT_reg6<-coeftest(FT_reg6, vcov= vcovHC, type= "HC1") 

### Policy Positions ###
# racial policy
Pol_reg1<-lm(racialpolicy_scale~ Treatment, data= data)
Pol_reg7<-coeftest(Pol_reg1, vcov= vcovHC, type= "HC1") 

# non racial policy
Pol_reg2<-lm(nonracialpolicy_scale~ Treatment, data= data)
Pol_reg8<-coeftest(Pol_reg2, vcov= vcovHC, type= "HC1") 

### Participation ###
# political backlash participation
Part_reg1<-lm(backlash_pol~ Treatment, data= data)
Part_reg1<-coeftest(Part_reg1, vcov= vcovHC, type= "HC1") 

# personal backlash participation
Part_reg2<-lm(backlash_person~ Treatment, data= data)
Part_reg2<-coeftest(Part_reg2, vcov= vcovHC, type= "HC1") 

# political supportive participation
Part_reg3<-lm(support_pol~ Treatment, data= data)
Part_reg3<-coeftest(Part_reg3, vcov= vcovHC, type= "HC1") 

# personal supportive participation
Part_reg4<-lm(support_person~ Treatment, data= data)
Part_reg4<-coeftest(Part_reg4, vcov= vcovHC, type= "HC1") 

#### Exporting Regressions ####

### Table F1 ###
stargazer(SMC_reg1, SMC_reg2, SMC_reg3,
          align= T,
          column.labels = c("Whites Demographic Minority", "Whites Political Minority", "Whites Cultural Minority"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table F2 ###
stargazer(SC1,
          align= T,
          dep.var.labels = c("Status Change"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table F3 ###
stargazer(Scale_reg1, Scale_reg2, Scale_reg3,
          align= T,
          column.labels = c("Symbolic Threat", "Realistic Threat", "Prototypicality Threat"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table F4 ###
stargazer(FT_reg1, FT_reg2, FT_reg3, FT_reg5,
          align= T,
          column.labels = c("Black FT", "Latino FT", "Asian FT", "BLM FT"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table F5 ###
stargazer(FT_reg4, FT_reg6,
          align= T,
          column.labels = c("White FT", "Alt Right FT"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table F6 ###
stargazer(Pol_reg1, Pol_reg2,
          align= T,
          column.labels = c("Racial Policy Scale", "Nonracial Policy Scale"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment"),
          star.cutoffs = c(0.05, 0.01, 0.001))

### Table F7 ###
stargazer(Part_reg1, Part_reg2, Part_reg3, Part_reg4,
          align= T,
          column.labels = c("Political Backlash", "Personal Backlash",
                            "Political Supportive", "Personal Supportive"),
          covariate.labels = c ("Cultural Shift Treatment", "Political Shift Treatment", 
                                "Population Treatment"),
          star.cutoffs = c(0.05, 0.01, 0.001))
